import { reactive } from 'vue'

export interface IArticle {
    type: string,
    id: string | number,
    title: string,
    shorter: string,
    keywords: string,
    description: string,
    pic: string,
    is_active: boolean,
    is_recommend: boolean,
    sort: string | number,
    content: string
}


export default function useArticleModel() {
    //初始化数据
    const iArticleModel = (): IArticle => {
        return {
            type: '',
            id: 0,
            title: '',
            shorter: '',
            keywords: '',
            description: '',
            pic: '',
            is_active: false,
            is_recommend: false,
            sort: '',
            content: ''
        }
    }

    // 菜单验证规则
    const articleRules = reactive({
        sort: [{
            required: true,
            message: '请选择分类！',
            trigger: 'blur',
        }],
        title: [{
            required: true,
            message: '请文章标题！',
            trigger: 'blur',
        }, {
            max: 255,
            message: '最大长度255位',
            trigger: 'blur'
        }],
        shorter: [{
            max: 32,
            message: '短标题最大长度32位!',
            trigger: 'blur'
        }],
        keywords: [{
            max: 255,
            message: '关键字最大长度255位!',
            trigger: 'blur'
        }],
        description: [{
            max: 255,
            message: '简介最大长度255位!',
            trigger: 'blur'
        }]
    })

    return { iArticleModel, articleRules }
}